/*
 * @Author: liaoxin
 * @Date: 2022-03-08 17:34:24
 * @LastEditors: liaoxin
 * @LastEditTime: 2022-06-09 14:10:30
 * @FilePath: \personnelmanage\src\pages\CustomerManage\Customer\List\edit\index.tsx
 */
import React from "react";
import { UdPageHeader, http } from '@/lib';
import { Input, Form, message, Modal } from 'antd';
import './index.scss'
import { BrandInfoEditTable } from "../../component/BrandInfoEditTable";
import apis from './../../../../../apis/CustomerManage'
import Usapis from './../../../../../apis/UserManagement/index'



export default class CustoemrEdit extends React.Component<any> {

    state = {
        tableData: []
    }

    //提交表单
    private hendleSubmit = (tableData: any[]) => {
        if (tableData.indexOf(false) === -1) {
            Modal.confirm({
                title: `编辑客户`,
                content: `确认修改该客户吗？`,
                onOk: () => {
                    return http.post(Usapis.updateCustomer, {
                        customerUpdateAgentReqVos: tableData
                    }).then(res => {
                        message.success("编辑成功！")
                        let ZdParams = {
                            brandCode: "",
                            dealerCode: this.props.match.params?.agentCode
                        }
                        tableData.forEach((item, index) => {
                            setTimeout(() => {
                                ZdParams.brandCode = item.brandCode
                                http.post(apis.pushUpdateDealerZd, ZdParams).then(resp => {
                                })
                            }, index * 3000);
                        })
                        this.props.history.goBack()
                    })
                }
            })
        }
    }

    componentWillMount() {
        http.get(apis.BelongBrandCompany, { params: { agentCode: this.props.match.params?.agentCode, type: 0 } }).then(res => {
            this.setState({ tableData: res.data })
        })
    }

    render() {
        return <div className="customer-mg-add-box">
            <UdPageHeader title="维护品牌信息" onBack />
            <Form className="customer-edit-form-box">
                <Form.Item label="客户名称" >
                    <Input value={this.props.match.params?.agentName} disabled />
                </Form.Item>
                <Form.Item label="客户编码" required>
                    <Input disabled value={this.props.match.params?.agentCode} />
                </Form.Item>
            </Form>
            <BrandInfoEditTable
                agentCode={this.props.match.params?.agentCode}
                type="编辑"
                setData={this.state.tableData}
                history={this.props.history}
                getData={(data) => {
                    this.hendleSubmit(data)
                }} />
        </div>
    }
}